// 一企一档
const app = getApp()
const { listApi } = require('../../../api/services/businessInfo/index')

Page({
  data: {
    comId: '',
    user: {},
  },

  //获取详情数据
  async getListData() {
    let params = { comId: this.data.comId }
    const res = await listApi(params)
    if (res.code != 200) {
      return app.toast(res.msg)
    }
    let list = res.data.base
    let newList = Object.assign(this.data.user, list)
    this.setData({ user: newList })
  },

  // 更改树形结构
  getAllTreeNode(arr, temp) {
    let arrNew = []
    for (var i = 0; i < arr.length; i++) {
      if (arr[i].parentId == temp) {
        arrNew.push(arr[i])
        arr[i].children = this.getAllTreeNode(arr, arr[i].id)
      }
    }
    return arrNew
  },

  getIndustryArr(data) {
    let obj = {}
    const newArr = data.map(item => {
      let key = item.name
      if (item.children) {
        let value = item.children.map(item1 => {
          return item1.name
        })
        obj[key] = value
      }
    })

    this.setData({
      citys: obj,
    })

    let newClums = [
      {
        values: Object.keys(obj),
        className: 'column1',
      },
      {
        values: obj['商贸行业'],
        className: 'column2',
        defaultIndex: 2,
      },
    ]

    this.setData({
      columns: newClums,
    })
  },

  onLoad: function (options) {
    this.setData({ comId: options.comid })

    this.getListData()
  },
})
